package com.company.word.servlet;

import com.company.word.dao.IWordDAO;
import com.company.word.dao.WordDAOImpl;
import com.company.word.pojo.Word;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet("/findcheck")
public class FindCheckServlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		// HttpServletRequest req 
		// Tomcat自动创建的对象，会把用户的请求信息放入
		
//		HttpServletResponse resp
		// Tomcat自动创建的对象, 通过它给用户发信息
		
		// 1. 获取用户提交的参数
		String word = req.getParameter("word");

		IWordDAO dao = new WordDAOImpl();
		Word w=new Word();
		try {
			w =  dao.findByWord(word);
			if(w!=null)
			{
				resp.setHeader("Content-Type","text/html;charset=utf-8");
				resp.getWriter().print("查找成功，即将为您跳转主页......");
				resp.getWriter().print(w.toString());
				resp.setHeader("refresh","3,url=dirct.html");
			}
			else
			{
				resp.getWriter().print("find fail");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

		
		
	}
	

}
